import {getProvinceList, getCityListById} from "@/api/common/index";
let AREAMP = [
    {label: "所属省份", level: '1', name: 'provinceCode',child: []},
    {label: "所属市", level: '2', name: 'cityCode', child: []},
    {label: "所属县区", level: '3', name: 'areaCode', child: []},
    {label: "所属镇/街道", level: '4', name: 'streetCode', child: []}
]
export default {
  data(){
    return {
      currentTapArea: {}
    }
  },
  methods: {
    initAreaMap(){
      let _self = this
      return new Promise((resolve, reject) => {
        let arr = []
        arr = AREAMP.filter(item=> {
          let idx = _self.areaMap.findIndex(ara=> ara.name== item.name)
          if(idx != -1){
            item = Object.assign(item, _self.areaMap[idx])
            return true
          }else return false
        });
        resolve(arr)
      })
    },
    getAreaList(key, id){
      let api = (key == 'province' ? getProvinceList : getCityListById)
      return new Promise((resolve, reject) => {
        api(id).then((res) => {
          resolve(res.data)
        });
      })
    }
  },
}